package com.itheima.appserver.config;

import com.itheima.commons.pojo.User;

public class MyThreadLocal {

    private final static ThreadLocal<User> threadLocal = new ThreadLocal<>();

    //把user设置到线程上
    public static void setUser(User user){
        threadLocal.set(user);
    }
    //获取当前线程的user
    public static User getUser(){
        return threadLocal.get();
    }
    //移除当前线程的user
    public static void reUser(){
        threadLocal.remove();
    }
    //获取当前线程上user的id
    public static Long getUserId(){
        return threadLocal.get().getId();
    }
}
